<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Admin\GoodsClass;
use Illuminate\Http\Request;
use App\Services\GoodsClassService;
use App\Services\UploadService;

class GoodsClassController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(GoodsClassService $goods_class_service)
    {
        $model = GoodsClass::all();
        $data = $goods_class_service->get_tree_classes($model);
//        dd($data);
        return view('admin.admin_goods_classes.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(GoodsClassService $goods_class_service)
    {
        //
        $model = GoodsClass::all();
        $data = $goods_class_service->get_tree_classes($model);
        return view('admin.admin_goods_classes.add',compact('data'));

    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        GoodsClass::create($request->except('_token','file','rate','tags'));
        return ['status'=>200,'msg'=>'成功'];
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    //缩略图上传
    public function goods_class_upload(Request $request,UploadService $upload_service)
    {
//        dd($request->all());
        $pic = '';
        if($request->hasFile('file')){
            //参数2 配置的节点名称
            $ret = $request->file('file')->store('','goods_class_thumb');
            $pic = '/uploads/goods_class_thumb/'.$ret;
        }
        return ['status'=>200,'url'=>$pic];
//        $upload_service->goods_class();
    }
}
